<template>
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="4" labelWidth="85" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <!-- 列筛选-->
    <FilterTable
      ref="table"
      columnsRef="zxWhMainPage"
      :columns="tableColumns"
      :fetchapi="fetchapi"
      :params="fetchParams"
      :onRowSelectChange="handleRowSelectChange"
      :datakey="'rows'"
      selectionType="single"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls">
        <!-- <el-button size="small" type="primary" @click="handleUpload">上传</el-button>
        <el-button size="small" type="primary" @click="handleCheckR3Log">查看R3日志</el-button>-->
      </template>
    </FilterTable>

    <Drawer :visible.sync="emitVisible" title="装饰件列表" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <emitStock :getdata="setEmitdata" @close="emitCloseHandle" @addChange="emitChange" />
    </Drawer>
  </div>
</template>

<script>
import { messageAction } from '@/utils';
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
import dictCode from '@/utils/dictCode';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import emitStock from './emitStock.vue';
import { getDecorativePartOutIn, getDecorativePartInfo } from '@/api/part/qualityManagement/decorativePartsExit';
// 维护工具主文件
export default {
  name: 'partDecorativePartsExit',
  components: {
    emitStock
  },
  mixins: [dictionary],
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      tableColumns: this.createTableColumns(),
      showSupplierSelecter: false, // 是否显示供应商选择
      quertR3DialogVisible: false, // 是否显示查看r3日志
      fetchapi: getDecorativePartOutIn,
      fetchParams: { xhrAbort: false },
      setEmitdata: {},
      setDetaildata: {},
      emitVisible: false,
      orderTypeList: [], // 订单类型列表(回显用)
      selectedOrderList: [], // 选中的订单列表
      partList: [], // 传递给编辑\新建订单的配件列表
      checkR3LogBillNo: '' // 查看r3日志的订单编号
    };
  },

  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {
    // this.getlist();
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '装饰派工单号',
          fieldName: 'BILL_NO'
        },
        {
          type: 'INPUT',
          label: '出库日期',
          initialValue: [moment(new Date()).format('YYYY-MM-DD')],
          fieldName: 'ORDER_DATE',
          // readonly: true,
          disabled: true
        },
        // {
        //   type: 'INPUT',
        //   label: '领料人',
        //   fieldName: 'vSupplyId',
        //   rules: [{ required: true, message: '请选择领料人', trigger: 'blur' }],
        //   placeholder: '',
        //   unitRender: () => {
        //     return <el-button slot="append" icon="el-icon-search" onClick={this.showProvideSearchHelper}></el-button>;
        //   },
        //   readonly: true
        // },
        // {
        //   type: 'SELECT',
        //   label: '领用人',
        //   fieldName: 'whManagerId',
        //   placeholder: '请输入...',
        //   itemList: [],
        //   rules: [{ required: true, message: '请输入领用人', trigger: 'blur' }],
        //   disabled: true,
        //   unitRender: props => {
        //     return <el-button icon="el-icon-search" onClick={() => this.searchReceiptorFun()}></el-button>;
        //   }
        // },
        {
          type: 'INPUT',
          label: '牌照号',
          fieldName: 'LICENSE_TAG'
        }
        // },
        // {
        //   type: 'RANGE_DATE',
        //   label: '出库日期',
        //   fieldName: 'deliveryTimeFrom|deliveryTimeTo',
        //   initialValue: [moment(new Date()).format('YYYY-MM-DD'), moment(new Date()).format('YYYY-MM-DD')],
        //   placeholder: '选择日期',
        //   valueFormat: 'yyyy-MM-dd'
        // }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: '',
          fixed: 'left',
          width: 60,
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.emitFun(props.row)} disabled={this.isEmit(props)}>
                  编辑
                </el-button>
              </div>
            );
          }
        },
        {
          title: '装饰派工单号',
          dataIndex: 'billNo',
          filterType: 'input',
          sorter: true,
          filter: true
        },
        {
          title: '对应整车销售单号',
          dataIndex: 'saleOrderNo',
          filterType: 'input',
          sorter: true,
          filter: true
        },
        {
          title: '牌照号',
          dataIndex: 'licenseTag',
          filterType: 'input',
          sorter: true,
          filter: true
        },
        {
          title: '底盘号',
          dataIndex: 'vin',
          minWidth: 150,
          showOverflowTooltip: true,
          filterType: 'input',
          sorter: true,
          filter: true
        },
        {
          title: '客户代码',
          dataIndex: 'customerNo',
          filterType: 'input',
          sorter: true,
          filter: true
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          showOverflowTooltip: true,
          filterType: 'input',
          sorter: true,
          filter: true
        },
        {
          title: '派工日期日期',
          dataIndex: 'orderDate',
          dateFormat: 'yyyy-MM-dd',
          filterType: 'date-range',
          sorter: true,
          filter: true
        },
        {
          title: '工单状态',
          dataIndex: 'status',
          filterType: 'checkbox',
          sorter: true,
          filter: true,
          filterItems: this.createDictList('9704'),
          render: props => {
            return <span>{this.createDictText(props.row.status, '9704')}</span>;
          }
        },
        {
          title: '操作员',
          dataIndex: 'whManagerId',
          filterType: 'input',
          sorter: true,
          filter: true
        },
        {
          title: '车型代码',
          dataIndex: 'model',
          filterType: 'input',
          sorter: true,
          filter: true
        }
      ];
    },
    searchReceiptorFun() {
      this.showSearchReceiptor = true;
    },
    // 获取数据字典数据
    // async getlist() {
    //   let roleParam = { role: dictCode.MATERIAL_AVAILABLE };
    //   // 获取领料人
    //   const res = await searchRoleByCode(roleParam);
    //   this.topFilterList[3].itemList = res.data.map(x => ({ text: x.employeeName, value: x.userId }));
    // },
    // 点击查看r3日志
    handleCheckR3Log() {
      if (this.selectedOrderList.length) {
        this.checkR3LogBillNo = this.selectedOrderList[0].orderNo;
        this.quertR3DialogVisible = true;
      } else {
        messageAction('请选择需要操作的装饰件', 'warning');
      }
    },
    isEmit(data) {
      return false;
    },
    emitFun(data) {
      // this.queryAllOrderTypeInfoList();
      this.queryBillPartList(data.billNo);
    },
    emitChange(val, index) {
      console.log(val, 'table值');
      console.log(index, 'index');
      this.emitVisible = false;
      this.fetchParams = { ...this.fetchParams };
      //  this.selectColumns[0].storageName='11110';
    },
    emitCloseHandle() {
      this.emitVisible = false;
    },
    // 查询该装饰派工单的详细配件情况
    async queryBillPartList(billNo) {
      let res = await getDecorativePartInfo({ billNo: billNo });
      let obj = {};
      console.log(res.data);
      this.setEmitdata = res.data;
      this.emitVisible = true;
    },
    // 供应商选择点击确定
    handleDealerSelectConfirm(e) {
      this.topFilterList.find(item => item.fieldName == 'vSupplyId').initialValue = e.customerCode;
    },
    // 切换供应商选择展示
    showProvideSearchHelper() {
      this.showSupplierSelecter = true;
    },
    handleRowSelectChange(e) {
      this.selectedList = e;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler(val, type) {
      // 关闭
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
